package demoMod.invincibleOne.powers;

import com.evacipated.cardcrawl.modthespire.lib.*;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.monsters.exordium.Hexaghost;
import demoMod.invincibleOne.characters.InvincibleOne;
import javassist.CtBehavior;

public class HexaghostPatch {
    @SpirePatch(
            clz = Hexaghost.class,
            method = "takeTurn"
    )
    public static class PatchTakeTurn {
        @SpireInsertPatch(locator = Locator.class, localvars = {"d"})
        public static void Insert(Hexaghost hexaghost, @ByRef int[] _d) {
            if (AbstractDungeon.player instanceof InvincibleOne) {
                _d[0] = 7;
            }
        }

        private static final class Locator extends SpireInsertLocator {
            @Override
            public int[] Locate(CtBehavior ctMethodToPatch) throws Exception {
                Matcher finalMatcher = new Matcher.FieldAccessMatcher(AbstractPlayer.class, "currentHealth");
                int[] lines = LineFinder.findAllInOrder(ctMethodToPatch, finalMatcher);
                return new int[]{lines[0] + 1};
            }
        }
    }
}
